﻿using Coldairarrow.Util.Excel.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;

namespace Coldairarrow.Util.Excel.Util
{
    public class ParseExcelRuleUtil
    {
        public string RuleJson { get; set; } = string.Empty;
        public List<SheetRule> SheetRules { get; set; }
        public ParseExcelRuleUtil(string json)
        {
            this.RuleJson = json;
            this.ParsRule(json);
        }

        private void ParsRule(string json)
        {
            
            WorkBookRule workBookRule = JsonConvert.DeserializeObject<WorkBookRule>(json);
            if(workBookRule !=null)
            {
                this.SheetRules = workBookRule.SheetRules;
            }
        }

        public SheetRule GetRuleBySheetName(string sheetName)
        {
           var rule = this.SheetRules.Find(r => r.SheetName.Equals(sheetName));
           return rule;
        }

        public SheetRule GetRuleBySheetIndex(int sheetIndex)
        {
            var rule = this.SheetRules.Find(r => r.SheetIndex == sheetIndex);
            return rule;
        }
    }
}
